package com.ruoyi.web.controller.fantasy;

import java.util.List;

import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.huanzhidadi.fantasy.bean.domain.FantasyTitleAbility;
import com.ruoyi.fantasy.service.IFantasyTitleAbilityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 称号能力Controller
 * 
 * @author wanghui
 * @date 2020-04-11
 */
@Controller
@RequestMapping("/fantasy/fantasyTitleAbility")
public class FantasyTitleAbilityController extends BaseController
{
    private String prefix = "fantasy/fantasyTitleAbility";

    @Autowired
    private IFantasyTitleAbilityService fantasyTitleAbilityService;

    @RequiresPermissions("fantasy:fantasyTitleAbility:view")
    @GetMapping()
    public String ability()
    {
        return prefix + "/ability";
    }

    /**
     * 查询称号能力列表
     */
    @RequiresPermissions("fantasy:fantasyTitleAbility:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FantasyTitleAbility fantasyTitleAbility)
    {
        startPage();
        List<FantasyTitleAbility> list = fantasyTitleAbilityService.selectFantasyTitleAbilityList(fantasyTitleAbility);
        fantasyTitleAbilityService.transforData(list);
        return getDataTable(list);
    }

    /**
     * 导出称号能力列表
     */
    @RequiresPermissions("fantasy:fantasyTitleAbility:export")
    @Log(title = "称号能力", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyTitleAbility fantasyTitleAbility)
    {
        List<FantasyTitleAbility> list = fantasyTitleAbilityService.selectFantasyTitleAbilityList(fantasyTitleAbility);
        ExcelUtil<FantasyTitleAbility> util = new ExcelUtil<FantasyTitleAbility>(FantasyTitleAbility.class);
        return util.exportExcel(list, "ability");
    }

    /**
     * 新增称号能力
     */
    @GetMapping("/add/{titleId}")
    public String add(@PathVariable("titleId") String titleId, ModelMap mmap)
    {
        mmap.put("titleId", titleId);
        return prefix + "/add";
    }

    /**
     * 新增保存称号能力
     */
    @RequiresPermissions("fantasy:fantasyTitleAbility:add")
    @Log(title = "称号能力", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FantasyTitleAbility fantasyTitleAbility)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        fantasyTitleAbility.setId(String.valueOf(IdWorker.nextId()));
        fantasyTitleAbility.setCreateBy(user.getUserId().toString());
        return toAjax(fantasyTitleAbilityService.insertFantasyTitleAbility(fantasyTitleAbility));
    }

    /**
     * 修改称号能力
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        FantasyTitleAbility fantasyTitleAbility = fantasyTitleAbilityService.selectFantasyTitleAbilityById(id);
        mmap.put("fantasyTitleAbility", fantasyTitleAbility);
        return prefix + "/edit";
    }

    /**
     * 修改保存称号能力
     */
    @RequiresPermissions("fantasy:fantasyTitleAbility:edit")
    @Log(title = "称号能力", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FantasyTitleAbility fantasyTitleAbility)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        fantasyTitleAbility.setUpdateBy(user.getUserId().toString());
        return toAjax(fantasyTitleAbilityService.updateFantasyTitleAbility(fantasyTitleAbility));
    }

    /**
     * 删除称号能力
     */
    @RequiresPermissions("fantasy:fantasyTitleAbility:remove")
    @Log(title = "称号能力", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fantasyTitleAbilityService.deleteFantasyTitleAbilityByIds(ids));
    }
}
